%% Graph: Decomposition of domestic Pi(q) change 

    my_blue = ones(1,3)*0.3;
    my_red = ones(1,3)*0.4;
    my_yellow = ones(1,3)*0.6;
    my_gray = ones(1,3)*0.85;


    % Baseline counterfactual lines
    cost_component = (eqm_cf1.c./eqm.c).^(param.alpha_m*(1-param.sigma)*const.gamma)...
        .*(eqm_cf1.P_s/1).^(param.alpha_s*(1-param.sigma)*const.gamma)...
        .*(param.w/1).^((1-param.alpha_m-param.alpha_s)*(1-param.sigma)*const.gamma)...
        .*(param.w/1).^(1-const.gamma);
    demand_component = (eqm_cf1.D0./eqm.D0).^const.gamma;
    total = (eqm_cf1.Pi0./eqm.Pi0);
    check = total - cost_component.*demand_component;   

    % Export subsidy counterfactual lines
    cost_component2 = (eqm_cf0.c./eqm.c).^(param.alpha_m*(1-param.sigma)*const.gamma)...
        .*(eqm_cf0.P_s/1).^(param.alpha_s*(1-param.sigma)*const.gamma)...
        .*(param.w/1).^((1-param.alpha_m-param.alpha_s)*(1-param.sigma)*const.gamma)...
        .*(param.w/1).^(1-const.gamma);
    demand_component2 = (eqm_cf0.D0./eqm.D0).^const.gamma;
    total2 = (eqm_cf0.Pi0./eqm.Pi0);
    check2 = total2 - cost_component2.*demand_component2;


    % Baseline counterfactual + export subsidy counterfactual in one figure
    fig = figure('visible','off','DefaultAxesFontSize',12);
    hold on
    h(1) = plot(const.Qgrid, ones(param.Q,1),'LineWidth',0.5,'Color','black');
    h(2) = plot(const.Qgrid, cost_component, 'color', my_gray, 'LineStyle','-.','LineWidth',2.5);
    h(3) = plot(const.Qgrid, demand_component,'color', my_gray, 'LineStyle','--','LineWidth',2.5);
    h(4) = plot(const.Qgrid, total, 'color', my_gray, 'LineWidth',3.5);   
    h(5) = plot(const.Qgrid, cost_component2, 'color', my_blue, 'LineStyle','-.','LineWidth',2.5);
    h(6) = plot(const.Qgrid, demand_component2, 'color', my_red,'LineStyle','--','LineWidth',2.5);
    h(7) = plot(const.Qgrid, total2, 'color', my_yellow,'LineWidth',3.5);
    hold off
    legend(h([5 6 7 4]), 'Cost Component', 'Demand Component', 'Total Domestic Profit Shifter', 'Baseline', 'Location','northwest')
    ylabel('Counterfactual / Initial Equilibrium')
    xlabel('Quality')  
    ax = gca;
    ylim(ax,[0.9, 1.15]);    
    %exportgraphics(fig,'../../output/figures/fullmodel_Pi0_decomposition_subsidy.pdf') 
    exportgraphics(fig,'../../output/figures/Figure6_B.pdf') 



  
